// VBlockBuilder.cpp
// Implement class VBlockBuilder

#include "crossbit/VBlockBuilder.h"
#include "crossbit/VBlock.h"

using namespace crossbit;

VBlockBuilder::VBlockBuilder()
:bb_vblock(NULL)
{
}

VBlockBuilder::~VBlockBuilder()
{
				if (bb_vblock)
								delete bb_vblock;
}

// Default behavior: instantiate VBlock object
void VBlockBuilder::getReady(XTMemAddr pc)
{
				assert(bb_vblock == NULL);	// make sure block_ has been packed and delivered to user
				bb_vblock = new VBlock(pc);
				bb_vreg = 1;
}

// Default behavior: append the VInstruction into VBlock as long as it doesn't end
void VBlockBuilder::add(VInst *inst)
{
				bb_vblock->push_back(inst);
}

// Default behavior: never ends
bool VBlockBuilder::isEnd()
{
				return false;
}

// Default behavior: return the VBlock, and nullify the internal handler
VBlock *VBlockBuilder::wrapUp(XTMemAddr spc)
{
				VBlock *res = bb_vblock;
				bb_vblock = NULL;
				res->setVbNextSpc( spc );
				return res;
}
